package com.xiaohong.account.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.account.dao.AccountTblMapper;
import com.xiaohong.account.pojo.AccountTbl;
import com.xiaohong.account.service.AccountTblService;
import com.xiaohong.account.utils.ExceptionUtil;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountTblServiceImpl implements AccountTblService {

    @Autowired
    private AccountTblMapper accountTblMapper;


    /**
     * 条件+分页查询AccountTbl
     * @param accountTbl 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<AccountTbl> findPage(AccountTbl accountTbl, int page, int size){
        // 构建查询条件
        QueryWrapper<AccountTbl> queryWrapper = new QueryWrapper<AccountTbl>(accountTbl);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return accountTblMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询AccountTbl
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<AccountTbl> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return accountTblMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法AccountTbl
     * @param accountTbl
     * @return
     */
    @Override
    public List<AccountTbl> findList(AccountTbl accountTbl){
        // 构建查询条件
        QueryWrapper<AccountTbl> queryWrapper = new QueryWrapper<AccountTbl>(accountTbl);
        // 查询数据
        return accountTblMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除AccountTbl
     * @param id
     */
    @Override
    public void delete(Integer id){
        accountTblMapper.deleteById(id);
    }

    /**
     * 根据ID修改AccountTbl
     * @param accountTbl
     */
    @Override
    public void update(AccountTbl accountTbl){
        accountTblMapper.updateById(accountTbl);
    }

    /**
     * 增加AccountTbl
     * @param accountTbl
     */
    @Override
    public void add(AccountTbl accountTbl){
        accountTblMapper.insert(accountTbl);
    }

    /**
     * 根据ID查询AccountTbl
     * @param id
     * @return
     */
    @Override
    public AccountTbl findById(Integer id){
        return  accountTblMapper.selectById(id);
    }

    /**
     * 查询全部AccountTbl数据
     * @return
     */
    @Override
    public List<AccountTbl> findAll() {
        return accountTblMapper.selectList(null);
    }

}
